/*
*  Copyright 2019-2023 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.yangxu.hospital.system.modules.system.controller;

import com.yangxu.hospital.common.utils.PageResult;
import com.yangxu.hospital.logging.annotation.Log;
import com.yangxu.hospital.system.modules.system.domain.SysPatient;
import com.yangxu.hospital.system.modules.system.domain.dto.SysPatientDto;
import com.yangxu.hospital.system.modules.system.service.SysPatientService;
import com.yangxu.hospital.system.modules.system.domain.vo.SysPatientQueryCriteria;
import lombok.RequiredArgsConstructor;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
* @author 杨旭
* @date 2024-11-25
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "患者管理管理")
@RequestMapping("/api/sysPatient")
public class SysPatientController {

    private final SysPatientService sysPatientService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sysPatient:list')")
    public void exportSysPatient(HttpServletResponse response, SysPatientQueryCriteria criteria) throws IOException {
        sysPatientService.download(sysPatientService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询患者管理")
    @ApiOperation("查询患者管理")
    @PreAuthorize("@el.check('sysPatient:list')")
    public ResponseEntity<PageResult<SysPatientDto>> querySysPatient(SysPatientQueryCriteria criteria, Page<Object> page){
        return new ResponseEntity<>(sysPatientService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增患者管理")
    @ApiOperation("新增患者管理")
    @PreAuthorize("@el.check('sysPatient:add')")
    public ResponseEntity<Object> createSysPatient(@Validated @RequestBody SysPatient resources){
        sysPatientService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改患者管理")
    @ApiOperation("修改患者管理")
    @PreAuthorize("@el.check('sysPatient:edit')")
    public ResponseEntity<Object> updateSysPatient(@Validated @RequestBody SysPatient resources){
        sysPatientService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除患者管理")
    @ApiOperation("删除患者管理")
    @PreAuthorize("@el.check('sysPatient:del')")
    public ResponseEntity<Object> deleteSysPatient(@RequestBody List<Long> ids) {
        sysPatientService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}